/*------------------------------------------------------------------------------
 * Copyright 2012 NCR Corporation
 *------------------------------------------------------------------------------
 * All revision information is updated automatically from source code control
 * change records - please do not manually edit.
 *------------------------------------------------------------------------------
 *
 * $LastChangedRevision:: 2026                                     $
 * $LastChangedBy:: rb250096                                       $
 * $LastChangedDate:: 2012-04-07 18:34:30 -0400 (Sat, 07 Apr 2012) $
 */

package com.ncr.nep.dashboardcore.mvp.client;

import com.ncr.nep.dashboardcore.ui.client.TitleBarPanel;

/**
 * {@link WidgetViewBinder} that displays the wrapped Widget inside a
 * {@link TitleBarPanel} popup dialog.
 *
 * @author rb250096
 * @version $Revision: 2026 $
 */
public class DialogViewBinder<T extends Presenter> extends WidgetViewBinder<T>
        implements DialogView {

    //--------------------------------------------------------------------------
    //
    //  Fields
    //
    //--------------------------------------------------------------------------

    /**
     * The popup panel containing the root widget.
     */
    protected TitleBarPanel popup;

    /**
     * The width of the popup; this can be any valid CSS width value.
     */
    protected String popupWidth;

    /**
     * The height of the popup; this can be any valid CSS height value.
     */
    protected String popupHeight;

    //--------------------------------------------------------------------------
    //
    //  Constructors
    //
    //--------------------------------------------------------------------------

    /**
     * Constructor.
     */
    public DialogViewBinder() {
        super();
    }

    /**
     * Constructor.
     *
     * @param popupWidth The width of the popup; this can be any valid CSS width
     *                   value.
     * @param popupHeight The height of the popup; this can be any valid CSS
     *                    height value.
     */
    public DialogViewBinder(String popupWidth, String popupHeight) {
        super();

        this.popupWidth = popupWidth;
        this.popupHeight = popupHeight;
    }

    //--------------------------------------------------------------------------
    //
    //  Methods
    //
    //--------------------------------------------------------------------------

    @Override
    public void show(String title) {
        this.popup = new TitleBarPanel();
        this.popup.setTitle(title);
        if(this.popupWidth != null) {
            this.popup.setWidth(this.popupWidth);
        }
        if(this.popupHeight != null) {
            this.popup.setHeight(this.popupHeight);
        }
        this.popup.setGlassEnabled(true);
        this.popup.setWidget(this);
        this.popup.centerTopBiased();
    }

    @Override
    public void close() {
        this.popup.hide();
    }
}
